package com.example.goukakuproject;

import com.leftMenuHelper.Lession;
import com.leftMenuHelper.LessionAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Toast;

public class GKSearchtab extends Activity {

	int bai = 0, trinhDo = 0;
	int soLuongTu;
	String textDisPlay = "";
	Lession lessonData[];
	boolean searchTu = false, searchKanji = false, searchNguPhap = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_gksearchtab);
		Intent callerIntent=getIntent();
		Bundle packageFromCaller = callerIntent.getBundleExtra("SearchIntent");
		bai = packageFromCaller.getInt("bai");
		trinhDo = packageFromCaller.getInt("trinhdo");
		Toast.makeText(this, "Trình độ N" + trinhDo + ". Bài " + bai, Toast.LENGTH_SHORT).show();
		final EditText edtSearch = (EditText) findViewById(R.id.txtSearch);
		final RadioButton radioTu = (RadioButton) findViewById(R.id.rbtnVocab);
		final RadioButton radioKanji = (RadioButton) findViewById(R.id.rbtnKanji);
		final RadioButton radioNguPhap = (RadioButton) findViewById(R.id.rbtnGrammar);
		final ListView listViewSearch = (ListView)findViewById(R.id.lvSearchResult); 
		radioTu.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				searchTu = true;
				searchKanji = false;
				searchNguPhap = false; 
				soLuongTu = 40;
				textDisPlay = "Từ số ";
				lessonData = new Lession[soLuongTu];       
		        for (int i = 0; i< soLuongTu; i++){
		        	lessonData[i] =  new Lession(R.drawable.ic_launcher, textDisPlay + (i+1));
		        }
		        LessionAdapter adapter = new LessionAdapter(GKSearchtab.this,R.layout.listview_item_row, lessonData);                                      
		        listViewSearch.setAdapter(adapter);
			}
		});	
		radioKanji.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				searchTu = false;
				searchKanji = true;
				searchNguPhap = false;
				soLuongTu = 40;
				textDisPlay = "Chữ Hán số ";
				lessonData = new Lession[soLuongTu];       
		        for (int i = 0; i< soLuongTu; i++){
		        	lessonData[i] =  new Lession(R.drawable.ic_launcher, textDisPlay + (i+1));
		        }
		        LessionAdapter adapter = new LessionAdapter(GKSearchtab.this,R.layout.listview_item_row, lessonData);                                      
		        listViewSearch.setAdapter(adapter);
			}
		});
		
		radioNguPhap.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				searchTu = false;
				searchKanji = false;
				searchNguPhap = true;
				soLuongTu = 40;
				textDisPlay = "Ngữ pháp số ";
				lessonData = new Lession[soLuongTu];       
		        for (int i = 0; i< soLuongTu; i++){
		        	lessonData[i] =  new Lession(R.drawable.ic_launcher, textDisPlay + (i+1));
		        }
		        LessionAdapter adapter = new LessionAdapter(GKSearchtab.this,R.layout.listview_item_row, lessonData);                                      
		        listViewSearch.setAdapter(adapter);  
			}
		});				        
		          
        listViewSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
		 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {	
				
			}
			
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.gksearchtab, menu);
		return true;
	}

}
